Add generic type in datagrid#10607
Closed
ogustavo-pereira wants to merge 1 commit intomarmelab:masterfrom
Closed
Conversation
djhi
suggested changes
Apr 9, 2025
Comment on lines
+121
to
+124
| const fixedForwardRef = <T, P = {}>( | ||
| render: (props: P, ref: React.Ref<T>) => React.ReactNode | ||
| ): ((props: P & React.RefAttributes<T>) => React.ReactNode) => | ||
| React.forwardRef(render) as any; |
Contributor
There was a problem hiding this comment.
Can you rename this to genericForwardRef (just like our genericMemo) and extract it in its own file directly under src? I have a feeling we're going to use it elsewhere
| ): ((props: P & React.RefAttributes<T>) => React.ReactNode) => | ||
| React.forwardRef(render) as any; | ||
|
|
||
| const WDatagrid = <RecordType extends RaRecord = any>( |
Contributor
There was a problem hiding this comment.
WDatagrid? I suggest DatagridComponent
| import { Identifier, RaRecord } from 'ra-core'; | ||
|
|
||
| export type RowClickFunction = <RecordType extends RaRecord = RaRecord>( | ||
| export type RowClickFunction<RecordType extends RaRecord = RaRecord> = ( |
Contributor
There was a problem hiding this comment.
We use this in SimpleListItem from SimpleList too. Can you make it accept a RecordType as well?
Member
|
We're introducing an alternative Datagrid component called DataTable that is, by default, generic. It will be released in react-admin 5.8. We won't be adding new updates to Datagrid, as we want to encourage the new component. So I'll close your PR and the related issue. Thanks anyway for your contribution. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Closes #10595
Describe the problem this PR solves
Solution
Since the datagrid is a React.forwardRef type component, I can't create a generic one easily, so I need help to solve and bring the best solution to this challenge.
I used the article below as a basis to solve the problem
https://www.totaltypescript.com/forwardref-with-generic-components
Variable names are for illustration purposes only, they can be better planned if the solution is to your liking.
Describe the solution this PR implements
How To Test
In the datagrid component itself, you can create a test component passing a generic and seeing if this generic is going to the rowClick
At first I focused only on rowClick, which is my main problem today, if you need other places we can add it
Describe the steps required to test the changes
Additional Checks
masterfor a bugfix or a documentation fix, ornextfor a featureAlso, please make sure to read the contributing guidelines.